package com.grass.p019lv.fragment;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager.widget.ViewPager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.APPLink;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.AdInfoBean;
import com.androidx.p013lv.base.glide.GlideUtils;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.service.AdClickService;
import com.androidx.p013lv.base.utils.AdUtils;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.invention.adapter.MyBannerAdapter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.google.android.material.tabs.TabLayout;
import com.grass.appointment.databinding.FragmentAppointmentDynamicBinding;
import com.grass.appointment.dialog.SelectPicDialog;
import com.grass.appointment.fragment.DynamicAppointmentFragment;
import com.grass.appointment.fragment.DynamicTypeFragment;
import com.grass.p019lv.bean.PiazzaBean;
import com.grass.p019lv.databinding.FragmentAppointmentPiazzaBinding;
import com.grass.p019lv.novel.activity.AudioBookActivity;
import com.grass.p019lv.viewmodel.PiazzaModel;
import com.gyf.immersionbar.ImmersionBar;
import com.youth.banner.indicator.RectangleIndicator;
import com.youth.banner.listener.OnBannerListener;
import java.util.ArrayList;
import java.util.List;

/* renamed from: com.grass.lv.fragment.PiazzaAppointmentFragment */
public class PiazzaAppointmentFragment extends LazyFragment<FragmentAppointmentPiazzaBinding> {
    private APPLink appLink;
    private SelectPicDialog dialog;
    private DynamicAppointmentFragment dynamicAppointmentFragment;
    private SparseArray<LazyFragment> fragmentList;
    private boolean haveBanner;
    private PiazzaModel model;
    private List<String> titleList;

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_appointment_piazza;
    }

    public static PiazzaAppointmentFragment newInstance() {
        Bundle bundle = new Bundle();
        PiazzaAppointmentFragment piazzaAppointmentFragment = new PiazzaAppointmentFragment();
        piazzaAppointmentFragment.setArguments(bundle);
        return piazzaAppointmentFragment;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment, com.gyf.immersionbar.components.ImmersionOwner
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(getActivity()).titleBar(((FragmentAppointmentPiazzaBinding) this.binding).toolbar).init();
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        this.model = (PiazzaModel) new ViewModelProvider(this).get(PiazzaModel.class);
        this.titleList = new ArrayList();
        this.fragmentList = new SparseArray<>();
        this.titleList.add("關註");
        this.fragmentList.append(0, DynamicTypeFragment.newInstance(1));
        this.titleList.add("推薦");
        this.fragmentList.append(1, DynamicTypeFragment.newInstance(2));
        this.titleList.add("最新");
        this.fragmentList.append(2, DynamicTypeFragment.newInstance(0));
        this.titleList.add("我的");
        DynamicAppointmentFragment newInstance = DynamicAppointmentFragment.newInstance(SpUtils.getInstance().getUserInfo().getUserId());
        this.dynamicAppointmentFragment = newInstance;
        this.fragmentList.append(3, newInstance);
        ((FragmentAppointmentPiazzaBinding) this.binding).setClick(new OnClick());
        ViewGroup.LayoutParams layoutParams = ((FragmentAppointmentPiazzaBinding) this.binding).banner.getLayoutParams();
        layoutParams.height = UiUtils.getWindowWidth() / 2;
        ((FragmentAppointmentPiazzaBinding) this.binding).banner.setLayoutParams(layoutParams);
        ((FragmentAppointmentPiazzaBinding) this.binding).banner.setIndicator(new RectangleIndicator(getActivity()));
        ((FragmentAppointmentPiazzaBinding) this.binding).viewPager.setAdapter(new PiazzaAdapter(getChildFragmentManager(), 1));
        ((FragmentAppointmentPiazzaBinding) this.binding).tabLayout.addOnTabSelectedListener((TabLayout.OnTabSelectedListener) new TabLayout.OnTabSelectedListener() {
            /* class com.grass.p019lv.fragment.PiazzaAppointmentFragment.C29991 */

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabReselected(TabLayout.Tab tab) {
            }

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabSelected(TabLayout.Tab tab) {
                PiazzaAppointmentFragment.this.changeTabTextView(tab, true);
            }

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabUnselected(TabLayout.Tab tab) {
                PiazzaAppointmentFragment.this.changeTabTextView(tab, false);
            }
        });
        ((FragmentAppointmentPiazzaBinding) this.binding).tabLayout.setupWithViewPager(((FragmentAppointmentPiazzaBinding) this.binding).viewPager);
        ((FragmentAppointmentPiazzaBinding) this.binding).viewPager.setOffscreenPageLimit(4);
        ((FragmentAppointmentPiazzaBinding) this.binding).viewPager.setCurrentItem(1);
        ((FragmentAppointmentPiazzaBinding) this.binding).viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            /* class com.grass.p019lv.fragment.PiazzaAppointmentFragment.C30002 */

            @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
            public void onPageScrollStateChanged(int i) {
            }

            @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
            public void onPageScrolled(int i, float f, int i2) {
            }

            @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
            public void onPageSelected(int i) {
                if (i == 3 && ((FragmentAppointmentDynamicBinding) PiazzaAppointmentFragment.this.dynamicAppointmentFragment.binding).getStatus().intValue() == 1) {
                    ((FragmentAppointmentPiazzaBinding) PiazzaAppointmentFragment.this.binding).setStatus(1);
                } else {
                    ((FragmentAppointmentPiazzaBinding) PiazzaAppointmentFragment.this.binding).setStatus(0);
                }
            }
        });
        setBanner(AdUtils.getInstance().getAppointment(), SpUtils.getInstance().getString("domain"));
        this.model.getPiazzaData().observe(this, new Observer<BaseRes<PiazzaBean>>() {
            /* class com.grass.p019lv.fragment.PiazzaAppointmentFragment.C30013 */

            public void onChanged(BaseRes<PiazzaBean> baseRes) {
                PiazzaBean data;
                if (!(baseRes.getCode() != 200 || baseRes.getData() == null || (data = baseRes.getData()) == null || data.getList() == null)) {
                    List<PiazzaBean.ListBean> list = data.getList();
                    for (int i = 0; i < list.size(); i++) {
                        if (list.get(i).getType().equals("recommend")) {
                            ((FragmentAppointmentPiazzaBinding) PiazzaAppointmentFragment.this.binding).setOfficialImg(list.get(i).getImg());
                        }
                        if (list.get(i).getType().equals("normal")) {
                            ((FragmentAppointmentPiazzaBinding) PiazzaAppointmentFragment.this.binding).setEngagementImg(list.get(i).getImg());
                        }
                    }
                }
            }
        });
        this.model.setPiazzaData();
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onResume() {
        super.onResume();
        String logo = SpUtils.getInstance().getUserInfo().getLogo();
        if (!TextUtils.isEmpty(logo)) {
            ((FragmentAppointmentPiazzaBinding) this.binding).setImgCover(logo);
        }
    }

    private void setBanner(List<AdInfoBean> list, String str) {
        if (list == null || list.size() <= 0) {
            ((FragmentAppointmentPiazzaBinding) this.binding).banner.setVisibility(8);
            return;
        }
        ((FragmentAppointmentPiazzaBinding) this.binding).banner.setVisibility(0);
        ((FragmentAppointmentPiazzaBinding) this.binding).banner.setAdapter(new MyBannerAdapter(list, str, this));
        ((FragmentAppointmentPiazzaBinding) this.binding).banner.start();
        ((FragmentAppointmentPiazzaBinding) this.binding).banner.setOnBannerListener(new OnBannerListener() {
            /* class com.grass.p019lv.fragment.PiazzaAppointmentFragment.C30024 */

            @Override // com.youth.banner.listener.OnBannerListener
            public void OnBannerClick(Object obj, int i) {
                PiazzaAppointmentFragment.this.startAd((AdInfoBean) obj);
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void startAd(AdInfoBean adInfoBean) {
        if (adInfoBean.getJumpType() == 2) {
            try {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                intent.setData(Uri.parse(adInfoBean.getAdJump()));
                startActivity(intent);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            if (this.appLink == null) {
                this.appLink = new APPLink(getActivity());
            }
            this.appLink.urlLink(adInfoBean.getAdJump());
        }
        Intent intent2 = new Intent(getActivity(), AdClickService.class);
        intent2.putExtra("adId", adInfoBean.getAdId());
        getActivity().startService(intent2);
    }

    public static void setMineHead(ImageView imageView, String str) {
        GlideUtils.loadCircleHeadWhite(SpUtils.getInstance().getString("domain") + str, imageView);
    }

    public static void setOfficial(ImageView imageView, String str) {
        RequestManager with = Glide.with(imageView.getContext());
        ((RequestBuilder) ((RequestBuilder) ((RequestBuilder) with.load(SpUtils.getInstance().getString("domain") + str).placeholder((int) R.drawable.ic_btn_official)).error(R.drawable.ic_btn_official)).fallback(R.drawable.ic_btn_official)).into(imageView);
    }

    public static void setEngagement(ImageView imageView, String str) {
        RequestManager with = Glide.with(imageView.getContext());
        ((RequestBuilder) ((RequestBuilder) ((RequestBuilder) with.load(SpUtils.getInstance().getString("domain") + str).placeholder((int) R.drawable.ic_btn_engagement)).error(R.drawable.ic_btn_engagement)).fallback(R.drawable.ic_btn_engagement)).into(imageView);
    }

    public void changeTabTextView(TabLayout.Tab tab, boolean z) {
        if (tab.getCustomView() == null) {
            tab.setCustomView(R.layout.tab_layout_text);
        }
        TextView textView = (TextView) tab.getCustomView().findViewById(16908308);
        if (z) {
            textView.setTextAppearance(getContext(), R.style.TabLayoutPiazzaTextSize);
        } else {
            textView.setTextAppearance(getContext(), R.style.TabLayoutNormalPiazzaTextSize);
        }
    }

    /* renamed from: com.grass.lv.fragment.PiazzaAppointmentFragment$PiazzaAdapter */
    class PiazzaAdapter extends FragmentPagerAdapter {
        public PiazzaAdapter(FragmentManager fragmentManager, int i) {
            super(fragmentManager, i);
        }

        @Override // androidx.fragment.app.FragmentPagerAdapter
        public Fragment getItem(int i) {
            return (Fragment) PiazzaAppointmentFragment.this.fragmentList.get(i);
        }

        @Override // androidx.viewpager.widget.PagerAdapter
        public int getCount() {
            return PiazzaAppointmentFragment.this.fragmentList.size();
        }

        @Override // androidx.viewpager.widget.PagerAdapter
        public CharSequence getPageTitle(int i) {
            return (CharSequence) PiazzaAppointmentFragment.this.titleList.get(i);
        }
    }

    /* renamed from: com.grass.lv.fragment.PiazzaAppointmentFragment$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void userInfo() {
            if (!PiazzaAppointmentFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.USER_INFO_ACTIVITY).withInt(Key.USER_ID, SpUtils.getInstance().getUserInfo().getUserId()).withInt("type", 0).navigation();
            }
        }

        public void goMessage() {
            if (!PiazzaAppointmentFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.MESSAGE_ACTIVITY).withString(Key.TXT, "廣場").navigation();
            }
        }

        public void officialArea() {
            if (!PiazzaAppointmentFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.OFFICIAL_ACTIVITY).withString(Key.BACK_TITLE, "廣場").navigation();
            }
        }

        public void Fiction() {
            if (!PiazzaAppointmentFragment.this.isOnClick()) {
                Intent intent = new Intent(PiazzaAppointmentFragment.this.getActivity(), AudioBookActivity.class);
                intent.putExtra("pageType", 0);
                PiazzaAppointmentFragment.this.startActivity(intent);
            }
        }

        public void engagementArea() {
            if (!PiazzaAppointmentFragment.this.isOnClick()) {
                ARouter.getInstance().build(Constance.ENGAGEMENT_ACTIVITY).withString(Key.BACK_TITLE, "廣場").navigation();
            }
        }

        public void sendDynamic() {
            if (!PiazzaAppointmentFragment.this.isOnClick()) {
                if (PiazzaAppointmentFragment.this.dialog == null) {
                    PiazzaAppointmentFragment.this.dialog = new SelectPicDialog(PiazzaAppointmentFragment.this.getContext(), new View.OnClickListener() {
                        /* class com.grass.p019lv.fragment.PiazzaAppointmentFragment.OnClick.View$OnClickListenerC30031 */

                        public void onClick(View view) {
                            PiazzaAppointmentFragment.this.dialog.dismiss();
                            if (view.getId() == R.id.ll_video) {
                                ARouter.getInstance().build(Constance.SEND_DYNAMIC_ACTIVITY).withInt("type", 1).navigation();
                            } else if (view.getId() == R.id.ll_pic) {
                                ARouter.getInstance().build(Constance.SEND_DYNAMIC_ACTIVITY).withInt("type", 0).navigation();
                            }
                        }
                    });
                }
                PiazzaAppointmentFragment.this.dialog.show();
            }
        }
    }
}
